#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
int pos = 0;    // variable to store the servo position

int sensorPin = 0;     
int sensorValue = 0;  
int GreenledPin =  12;    // LED connected to digital pin 13
int RedledPin =  10;    // LED connected to digital pin 13



void setup() {
  Serial.begin(9600); 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
  myservo.write(180);
  pinMode(GreenledPin, OUTPUT);
  pinMode(RedledPin, OUTPUT);
  
}

void loop() {
  sensorValue = analogRead(sensorPin);
  float dist_mm = 1085534.81 * (float)pow((float)sensorValue, -1.2);
  Serial.println(dist_mm, DEC);    
  digitalWrite(GreenledPin, HIGH);
  digitalWrite(RedledPin, HIGH);
  delay(500);
  if (dist_mm <= 2500)
  {
   
    delay(360000);
  }
  digitalWrite(GreenledPin, LOW);
  digitalWrite(RedledPin, LOW);
  delay(2000);                                                    
  
}


void Dispense()
{
    digitalWrite(RedledPin, LOW);
    for(pos = 180; pos > 135; pos -= 1)
     {
       myservo.write(pos);
       delay(15); 
     }
    //myservo.write(135);
     for(pos = 135; pos > 45; pos -= 1)
     {
       myservo.write(pos);
       delay(15); 
     }
    for(pos = 45; pos < 180; pos += 1)
     {
       myservo.write(pos);
       delay(15); 
     }
     digitalWrite(RedledPin, HIGH);
     digitalWrite(GreenledPin, LOW);
}

void LED(int color, int BlinkRate)
{
  
}



